//
//  ControllLayer.m
//  lust
//
//  Created by fan on 13-4-1.
//
//
#import <Foundation/Foundation.h>
#import "ControllLayer.h"
@implementation ControllLayer
@synthesize gLayer;
-(id)init
{
    self=[super init];
    if (self) {
        CGSize s=[CCDirector sharedDirector].winSize;
        CCSpriteBatchNode* mgr=[CCSpriteBatchNode batchNodeWithFile:@"JoyStickMenu.png"];
        [self addChild:mgr];
        
        CCSprite* spriteNormal,*spriteSelected;
        CCMenuItemSprite* item_f;
        spriteNormal=[CCSprite spriteWithFile:@"JoyStickMenu.png" rect:CGRectMake((2+0)*11, 0, 11, 11)];
        spriteSelected=[CCSprite spriteWithFile:@"JoyStickMenu.png" rect:CGRectMake((2+5)*11, 0, 11, 11)];
        item_f=[CCMenuItemSprite itemWithNormalSprite:spriteNormal selectedSprite:spriteSelected target:self selector:@selector(onFire:)];
        CCMenu* menu =[CCMenu menuWithItems:item_f, nil];
        [menu alignItemsVertically];
        [menu setPosition:ccp(s.height-11*3-100, 3+11*2)];
        menu.anchorPoint=CGPointMake(0.5, 0.5);
        [self addChild:menu];
        mgr.position=menu.position;
        
        //up
        item_u_n=[CCSprite spriteWithTexture:mgr.texture rect:CGRectMake((0+0)*11, 0, 11, 11)];
        item_u_s=[CCSprite spriteWithTexture:mgr.texture rect:CGRectMake((0+5)*11, 0, 11, 11)];
        [item_u_n setPosition:ccp(item_f.position.x, item_f.position.y+11)];
        [item_u_s setPosition:ccp(item_f.position.x, item_f.position.y+11)];
        [mgr addChild:item_u_n];
        [mgr addChild:item_u_s];
        [item_u_s setVisible:NO];
        //left
        item_l_n=[CCSprite spriteWithTexture:mgr.texture rect:CGRectMake((1+0)*11, 0, 11, 11)];
        item_l_s=[CCSprite spriteWithTexture:mgr.texture rect:CGRectMake((1+5)*11, 0, 11, 11)];
        [item_l_n setPosition:ccp(item_f.position.x-11, item_f.position.y)];
        [item_l_s setPosition:ccp(item_f.position.x-11, item_f.position.y)];
        [mgr addChild:item_l_n];
        [mgr addChild:item_l_s];
        [item_l_s setVisible:NO];
        
        //right
        item_r_n=[CCSprite spriteWithTexture:mgr.texture rect:CGRectMake((0+3)*11, 0, 11, 11)];
        item_r_s=[CCSprite spriteWithTexture:mgr.texture rect:CGRectMake((0+8)*11, 0, 11, 11)];
        [item_r_n setPosition:ccp(item_f.position.x+11, item_f.position.y)];
        [item_r_s setPosition:ccp(item_f.position.x+11, item_f.position.y)];
        [mgr addChild:item_r_n];
        [mgr addChild:item_r_s];
        [item_r_s setVisible:NO];
        
        //down
        item_d_n=[CCSprite spriteWithTexture:mgr.texture rect:CGRectMake((1+3)*11, 0, 11, 11)];
        item_d_s=[CCSprite spriteWithTexture:mgr.texture rect:CGRectMake((1+8)*11, 0, 11, 11)];
        [item_d_n setPosition:ccp(item_f.position.x, item_f.position.y-11)];
        [item_d_s setPosition:ccp(item_f.position.x, item_f.position.y-11)];
        [mgr addChild:item_d_n];
        [mgr addChild:item_d_s];
        [item_d_s setVisible:NO];
        
        [self setIsTouchEnabled:YES];
    }
    return self;
}

-(void)onFire:(id)sender
{
}

-(void)registerWithTouchDispatcher
{
    [[CCDirector sharedDirector].touchDispatcher addTargetedDelegate:self priority:INT_MIN+1 swallowsTouches:YES];
}
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
    return YES;
}
-(void)ccTouchesEnded:(UITouch *)touches withEvent:(UIEvent *)event{}
-(void)ccTouchesMoved:(UITouch *)touches withEvent:(UIEvent *)event{}
-(void)ccTouchesCancelled:(UITouch *)touches withEvent:(UIEvent *)event
{}
@end
